package com.example.demo.service.impl;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
 * @author huangke
 * @description mockMVC
 * @date 2020/12/30
 */
@SpringBootTest
@AutoConfigureMockMvc
public class MockMvcTestCamunda {
    @Autowired
    private MockMvc mockMvc;

    @Test
    public void shouldReturnDefaultMessage() throws Exception {
        this.mockMvc.perform(get("/")).andDo(print()).andExpect(status().isOk())
                .andExpect(content().string(containsString("Hello, World")));
    }

    @Test
    public void test1() throws Exception {
        this.mockMvc.perform(get("/test1"))
                .andDo(print())
                .andExpect(status().isOk());
//                .andExpect(jsonPath("$.code").value("200"));
    }

    @Test
    @Transactional
    public void test2() throws Exception {
        this.mockMvc.perform(post("/test2/2"))
                .andDo(print())
                .andExpect(status().isOk());
//                .andExpect(jsonPath("$.code").value("200"));
    }

}